package com.ocom.payhandle.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ocom.common.entity.access.EntityDeptInfo;
import com.ocom.common.enums.DataSourceEnum;
import com.ocom.common.enums.MasterSlaveEnum;
import com.ocom.mysql.aspect.DataSourceAspect;
import com.ocom.payhandle.dao.IDaoDeptInfo;
import com.ocom.payhandle.service.DeptInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DeptInfoServiceImpl extends ServiceImpl<IDaoDeptInfo, EntityDeptInfo> implements DeptInfoService {

    @Autowired
    private IDaoDeptInfo iDaoDeptInfo;

    @DataSourceAspect(type= DataSourceEnum.PART_DB,companyId = "comId",isMaster = MasterSlaveEnum.SLAVE)
    @Override
    public EntityDeptInfo selectDeptName(Long comId, Long deptId) {
        QueryWrapper<EntityDeptInfo> wrapper = new QueryWrapper<>();
        wrapper.select("dept_name");
        wrapper.eq("com_id",comId);
        if(deptId!=null){
            wrapper.eq("dept_id",deptId);
        }
        wrapper.orderByDesc("update_time");
        wrapper.last("limit 1");
        return iDaoDeptInfo.selectOne(wrapper);
    }

}
